package com.kaixinff.kaixin001.common;

import java.io.IOException;
import java.net.HttpURLConnection;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.json.JSONException;

import com.kaixinff.kaixin001.wap.AddFriend;
import com.kaixinff.net.HttpClient;

public class GetUID {

	private static String URL = "http://bbs.snsfun.com/thread-121058-1-1.html";
	/**
	 * @param args
	 * @throws IOException 
	 * @throws JSONException 
	 */
	public static void main(String[] args) throws Exception{
		List<String> uidList = new ArrayList<String>();
		Pattern p = Pattern.compile("(http[:]//.+?/)");
		Matcher m = p.matcher(URL);
		if (!m.find()) {
			return;
		}
		String host = m.group(1);
		
		HttpClient client = new HttpClient();
		String cont = client.doGet(URL, null).getContent();
		
		while (true) {
			p = Pattern.compile("www[.]kaixin001[.]com/home/[?]uid=(\\d+)");
			m = p.matcher(cont);
			int index = 1;
			while (m.find(index)) {
				String uid = m.group(1);
				if (!uidList.contains(uid)) {
					uidList.add(uid);
					System.out.println("http://www.kaixin001.com/home/?uid=" + uid);
				}
				index = m.end(1);
			}
			
			p = Pattern.compile("<a href=\"([^<>]+?)\" class=\"next\">");
			m = p.matcher(cont);
			if (m.find()) {
				cont = client.doGet(host + m.group(1), URL).getContent();
			} else {
				break;
			}
		}
//		AddFriend.addFriend(uidList, "x");
	}

}
